package com.zj.leetcode.medium;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: algorithm
 * @description: 539. 最小时间差
 * @author: Zhang Bo
 * @create: 2022-01-13 17:32
 **/
public class MinimumTimeDifference {
    public static void main(String[] args) {
        List<String> times = new ArrayList<>();

        times.add("00:00");
        times.add("23:59");
        times.add("00:00");

        Solution solution = new MinimumTimeDifference().new Solution();
        System.out.println(solution.findMinDifference(times));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {

        /**
         * 转化成分钟去比较就好了，
         * 不要什么date工具类
         * @param timePoints
         * @return
         */
        public int findMinDifference(List<String> timePoints) {

            int[] arr = new int[timePoints.size()];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = Integer.parseInt(timePoints.get(i).substring(0, 2)) * 60 + Integer.parseInt(timePoints.get(i).substring(3));
            }
            Arrays.sort(arr);
            int min = Integer.MAX_VALUE;
            for (int i = 1; i < arr.length; i++) {
                min = Math.min(min, arr[i] - arr[i - 1]);
            }
            return Math.min(min, arr[0] + 1440 - arr[arr.length - 1]);

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
